package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.CabinetType;
import com.share.device.service.ICabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Tag(name = "柜机类型接口管理")
@RestController
@RequestMapping("/cabinetType")
public class CabinetTypeController extends BaseController {

    @Autowired
    private ICabinetTypeService cabinetTypeService;

    @Operation(summary = "分页获取柜机类型列表")
    @GetMapping("/list")
    public TableDataInfo cabinetTypelist(CabinetType cabinetType) {
        startPage();
        return getDataTable(cabinetTypeService.selectCabinetTypeList(cabinetType));
    }

    @Operation(summary = "获取全部柜机类型列表")
    @GetMapping("/all")
    public AjaxResult cabinetTypeAll() {
        return AjaxResult.success(cabinetTypeService.list());
    }

    @Operation(summary = "添加")
    @PostMapping
    public AjaxResult add(@RequestBody CabinetType cabinetType) {
        return toAjax(cabinetTypeService.save(cabinetType));
    }

    @Operation(summary = "修改")
    @PutMapping
    public AjaxResult update(@RequestBody CabinetType cabinetType) {
        return toAjax(cabinetTypeService.updateById(cabinetType));
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return toAjax(cabinetTypeService.removeByIds(Arrays.asList(ids)));
    }

    @Operation(summary = "根据id查询详情")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(cabinetTypeService.getById(id));
    }

}
